package com.icim.twqc.importer.service.impl;

import java.io.File;
import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.icim.entity.Ret_prd_in_twqc;
import com.icim.twqc.importer.service.IRetXmlImportService;
import com.icim.twqc.importer.entity.TwqcMfgFileXmlEntity;
import com.icim.twqc.importer.entity.TwqcMfgInfoXmlEntity;
import com.icim.twqc.importer.service.IRetPrdInTwqcService;
import com.icim.util.TimeUtil;
import com.icim.util.XmlConvertUtil;

@Transactional
@Service("retXmlImportTwqcService")
public class RetXmlImportServiceImpl implements IRetXmlImportService {
  
  @Autowired
  private IRetPrdInTwqcService retPrdInTwqcService;

  @Override
  public void importXMLProc(File xmlFile) {
      // 解析XML，将xml转换为对象实体
	  TwqcMfgFileXmlEntity xmlEntity = (TwqcMfgFileXmlEntity) XmlConvertUtil.file2ObjectForTwqc(xmlFile,
			  TwqcMfgFileXmlEntity.class);
	  List<TwqcMfgInfoXmlEntity> mfgInfoList = (List<TwqcMfgInfoXmlEntity>) xmlEntity.getMFGINFO();
	  String time = TimeUtil.getEvtTime();
	  for(TwqcMfgInfoXmlEntity mfgInfo : mfgInfoList)
	  {
		  Ret_prd_in_twqc retPrdInTwqc = new Ret_prd_in_twqc();
		  retPrdInTwqc.TwqcXml2Entity(mfgInfo);
		  retPrdInTwqc.setEVT_TIMESTAMP(time);
	    // 写入DB
		  retPrdInTwqcService.save(retPrdInTwqc);
	  }
  }
}
